#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <sstream>
#include <string.h>

using namespace std;

int replace(char *str)
{
  if (*str == 0)
  {
    cout << "wrong string\n";
    return 0;
  }

  char *tmp;
  tmp = new char[128];
//  tmp = (char *)malloc(128*sizeof(char));
  memset(tmp, 0, 128);
  int i = 0;
  while(*(str+i) != 0)
  {
    *(tmp+i) = *(str+i);
    i++;
  }

  int n = 0;
  i=0;
  while(*(tmp+i) != 0)
  {
    if (*(tmp+i) == ' ')
    {
      *(str+n) = '%';
      *(str+n+1) = '2';
      *(str+n+2) = '0';
      n += 2;
    }
    else
      *(str+n)=*(tmp+i);
    cout << *(tmp+i);
    i++;
    n++;
  }
  cout << endl;
//  memset(tmp, 0, 128);
//  free(tmp);
  delete[] tmp;
  tmp = NULL;
  return 0;
}

int main(int argc, char *argv[])
{
  if (argc<2)
  {
    cout << "test case file needed!\n";
    return 0;
  }

  char *filename = argv[1];
  ifstream fp(filename);
  char *str;
//  str = (char *)malloc(256*sizeof(char));
  str = new char[128];
  string in;
  getline(fp, in);
  int num;
  istringstream ss(in);
  ss >> num;
  cout << "test case number is: " << num << endl;
  int i = 1;
  while(getline(fp, in) && (i<=num))
  {
    int len = in.size();
    cout << "len is: " << len << " in is: " << in << endl;
    for(int j=0;j<len;j++)
      *(str+j) = in[j];
//    *(str+len) = '0';
    int m = 0;
    replace(str);
    while(*(str+m) != 0)
    {
      cout << *(str+m);
      m++;
    }
    cout << "\n------------------------------------------\n";
    memset(str, 0, 128);
    i++;
  }
 
//  free(str);
  delete[] str;
  return 0;
}
